//
//  SISSNetworkingManager+TenantProgress.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/1/2.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSNetworkingManager+TenantProgress.h"
#import "SISSRentOutModel.h"
#import "SISSTenantProgressRecordInfoModel.h"
#import "SISSTenantEntrustContractModel.h"
#import "SISSTenantIntentionRentOutModel.h"
#import "SISSTenantTakeLookModel.h"
#import "SISSTenantTakeLookAppointmentModel.h"
#import "SISSCommentModel.h"
#import "SISSTenantInfoModel.h"
#import "SISSNetworkingManager+File.h"

@implementation SISSNetworkingManager (TenantProgress)

//  4.2.6 删除租房进度 GET请求
- (void)deleteTenantProgressWithArbpId:(NSString *)arbpId successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"arbpId":arbpId
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_DELETE_TENANT_PROGRESS parameters:parameters success:^(id responseObject) {
        NSLog(@"4.2.6 删除租房进度 GET请求: responseObject-->%@",responseObject);
        
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.4.6 获取租客进度的信息 GET请求
- (void)requestTenantProgressRecordInfoWithArbpId:(NSString *)arbpId success:(void (^)(SISSTenantProgressRecordInfoModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"arbpId":arbpId
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_GET_TENANT_PROGRESS_INFO parameters:parameters success:^(id responseObject) {
        
        NSLog(@"4.4.6 获取租客进度的信息 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        
        SISSTenantProgressRecordInfoModel *model = [SISSTenantProgressRecordInfoModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.23.4  获取出租推荐的租客信息 GET请求
- (void)requestTenantRecommendRentOutWithArbpId:(NSString *)arbpId success:(void (^)(SISSRentOutModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    
    NSDictionary *parameters = @{
                                 @"arbpId":arbpId
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_TENANT_RECOMMEND_RENTOUT parameters:parameters success:^(id responseObject) {
        NSLog(@"4.23.4  获取出租推荐的租客信息 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        
        SISSRentOutModel *rentOutModel = [SISSRentOutModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(rentOutModel);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.23.5  获取租房进度意向出租 GET请求
- (void)requestTenantIntentionRentOutWithArbpId:(NSString *)arbpId success:(void (^)(SISSTenantIntentionRentOutModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"arbpId":arbpId
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_TENANT_INTENTION_RENTOUT parameters:parameters success:^(id responseObject) {
        NSLog(@"4.23.5  获取租房进度意向出租 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        
        SISSTenantIntentionRentOutModel *intendRentOutModel = [SISSTenantIntentionRentOutModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(intendRentOutModel);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
} 

// 4.29.4 添加承租方委托协议 (图文上传)
- (void)insertTenantEntrustContractWithParameters:(NSDictionary *)parameters imagesArray:(NSArray *)imagesArray successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    [SISSPublicSingleton shared].isHud = NO;
    [kNetworkManager uploadFileListWatermark:imagesArray success:^(id  _Nonnull responseObject) {
        NSLog(@"%@",responseObject);
        if ([responseObject[@"code"] integerValue] == 200) {
            NSArray *dataArr = responseObject[@"data"];
            NSDictionary *parameter = @{
                                        @"saId":[SISSUserAccount shared].saId,
                                        @"file":dataArr,
                                        };
            NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:parameter];
            [params addEntriesFromDictionary:parameters];
            
            [kNetworkNoUTF8Manager POSTWithURLString:URL_PROGRESS_INSERT_TENANT_ENTRUST_CONTRACT parameters:params success:^(id responseObject) {
                NSLog(@"4.29.4 添加承租方委托协议 (图文上传): responseObject-->%@",responseObject);
                
                if (successBlock) {
                    successBlock(responseObject);
                }
            } failure:^(NSError *error) {
                if (failedBlock) {
                    failedBlock(error);
                }
            }];
        }
    } failed:^(NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
}

// 4.45.1 获取租房进度带看预约记录 GET请求
- (void)requestTenantTakelookAppointmentWithArbpId:(NSString *)arbpId success:(void (^)(NSArray<SISSTenantTakeLookAppointmentModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"arbpId":arbpId
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_GET_TENANT_TAKELOOK_APPOINTMENT parameters:parameters success:^(id responseObject) {
        NSLog(@"4.45.1 获取租房进度带看预约记录 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *takelookArr = [NSArray yy_modelArrayWithClass:[SISSTenantTakeLookAppointmentModel class] json:dataArr];
        if (successBlock) {
            successBlock(takelookArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.45.3 获取租房进度带看详情 GET请求
- (void)requestTenantTakelookDetailWithLtlrId:(NSString *)ltlrId success:(void (^)(SISSTenantTakeLookModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"ltlrId":ltlrId
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_GET_TENANT_TAKELOOK_DETAIL parameters:parameters success:^(id responseObject) {
        
        NSLog(@"4.45.3 获取租房进度带看详情 GET请求: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        NSDictionary *dataDict = responseObject[@"data"];
        SISSTenantTakeLookModel *takeLookDetail = [SISSTenantTakeLookModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(takeLookDetail);
        }
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
    
}

// 4.45.6 获取租房进度带看记录 GET请求
- (void)requestTenantTakelookRecordWithArbpId:(NSString *)arbpId success:(void (^)(NSArray<SISSTenantTakeLookModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"arbpId":arbpId
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_GET_TENANT_TAKELOOK_RECORD parameters:parameters success:^(id responseObject) {
        NSLog(@"4.45.6 获取租房进度带看记录 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *takelookArr = [NSArray yy_modelArrayWithClass:[SISSTenantTakeLookModel class] json:dataArr];
        if (successBlock) {
            successBlock(takelookArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.45.7  获取租客进度带看经纪人评价租客详情 GET请求
- (void)requestCommentTakeLookBrokerCommentTenantInfoWithId:(NSString *)ID success:(void (^)(SISSCommentModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"id":ID
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_GET_TAKELOOK_BROKER_COMMENT_TENANT parameters:parameters success:^(id responseObject) {
        
        NSLog(@"4.45.7  获取租客进度带看经纪人评价租客详情 GET请求 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataDict = responseObject[@"data"];
        SISSCommentModel *model = [SISSCommentModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.45.8  获取租客进度带看租客评价经纪人详情 GET请求
- (void)requestCommentTakeLookTenantCommentBrokerInfoWithId:(NSString *)ID success:(void (^)(SISSCommentModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"id":ID
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_GET_TAKELOOK_TENANT_COMMENT_BROKER parameters:parameters success:^(id responseObject) {
        
        NSLog(@"4.45.8  获取租客进度带看租客评价经纪人详情 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataDict = responseObject[@"data"];
        
        SISSCommentModel *model = [SISSCommentModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.45.9  经纪人评价租客
- (void)insertBrokerCommentTenantWithParameters:(NSDictionary *)parameters success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kNetworkManager POSTWithURLString:URL_PROGRESS_INSERT_BROKER_COMMENT_TENANT parameters:parameters success:^(id responseObject) {
        NSLog(@"4.45.9  经纪人评价租客: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
} 

// 4.51.1 获取求租进度经纪人评价租客 GET请求
- (void)requestCommentBrokerCommentTenantInfoWithArbpId:(NSString *)arbpId success:(void (^)(SISSCommentModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"ltlrId":@"-1",
                                 @"arbpId":arbpId,
                                 @"comment_type":@(2)
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_GET_BROKER_COMMENT_TENANT parameters:parameters success:^(id responseObject) {
        
        NSLog(@"4.51.1 获取求租进度经纪人评价租客 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataDict = responseObject[@"data"];
        SISSCommentModel *model = [SISSCommentModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.51.2 获取求租进度租客评价经纪人 GET请求
- (void)requestCommentTenantCommentBrokerInfoWithArbpId:(NSString *)arbpId success:(void (^)(SISSCommentModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"ltlrId":@"-1",
                                 @"arbpId":arbpId,
                                 @"comment_type":@(2)
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_GET_TENANT_COMMENT_BROKER parameters:parameters success:^(id responseObject) {
        
        NSLog(@"4.51.2 获取求租进度租客评价经纪人 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataDict = responseObject[@"data"];
        SISSCommentModel *model = [SISSCommentModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.53.2  获取租房进度租客信息 GET请求
- (void)requestTenantEntrustContractTenantInfoWithArbpId:(NSString *)arbpId success:(void (^)(SISSTenantInfoModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"arbpId":arbpId
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_GET_TENANT_COMMISSION_TENANT_INFO parameters:parameters success:^(id responseObject) {
        NSLog(@"4.53.2  获取租房进度租客信息 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        SISSTenantInfoModel *model = [SISSTenantInfoModel yy_modelWithJSON:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.47.1 设置交易出租 GET请求
- (void)confirmTradeLeaseWithParameters:(NSDictionary *)parameters success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_BUYER_CONFIRM_TRADE_LEASE parameters:parameters success:^(id responseObject) {
        NSLog(@"4.47.1 设置交易出租 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 4.47.2 获取交易出租 GET请求
- (void)requestTradeLeaseInfoWithArbpId:(NSString *)arbpId success:(void (^)(SISSRentOutModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"arbpId":arbpId
                                 };
    
    [kNetworkManager GETWithURLString:URL_PROGRESS_GET_TRADE_LEASE parameters:parameters success:^(id responseObject) {
        NSLog(@"4.47.2 获取交易出租 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        SISSRentOutModel *rentOutInfo = [SISSRentOutModel yy_modelWithJSON:dataDict];
        
        if (successBlock) {
            successBlock(rentOutInfo);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

@end
